<?php

namespace App\Admin\Actions\WithdrawAction;

use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use App\Supports\Withdraw\WithdrawMoneyReturn;
use App\Services\ApplyGoldCoinWithdraw\BackFailedWithdrawCoins;

class ReturnFailedWithdraw extends RowAction
{
    public $name = '回退';
    
    public function handle(Model $model)
    {
	    if ($model->isPaid()) {
		    return $this->response()->error('仅提现失败未打款记录可回退');
	    }
	    
	    if ($model->status == 'pending'
		    or $model->status == 'confirmed'
		    or $model->status == 'failed') {
		    
	    	app(BackFailedWithdrawCoins::class)->back($model);
		    return $this->response()->success('失败提现已回退')->refresh();
		    
	    } else {
		    return $this->response()->error('仅提现失败未打款记录可回退');
	    }
    }
	
	public function dialog()
	{
		$this->confirm('确定回退此提现，请谨慎操作?');
	}
}
